package day08

/**
 * field
 *   属性信息
 * 类的定义
 */
fun main() {
    val player = Player0()
    player.name = " peter "

    println(player.name)


    //TODO:计算属性
    val content = player.content
    println(content)


    //TODO:防空竞态条件：如果一个类属性既可空又可变，那么引用它之前你必须保证它非空，一个办法用also标准函数
    player.saySomthing()




}

class Player0{
    var name:String = "  rose  "
        get() = field.capitalize()
        set(value) {
            field = value.trim()
        }


    //计算属性
    val content
        get() = (1..6).shuffled().first()

    //TODO:防空竞态条件：如果一个类属性既可空又可变，那么引用它之前你必须保证它非空，一个办法用also标准函数
    var words:String? = "sunday"

    fun saySomthing(){
        words?.also {
            println("hello ${it.toUpperCase()}")
        }
    }

}